<template>
  <div class="login_container">
    <div>
      <a-form :form="form" @submit="handleSubmit">
        <a-form-item>
           <a-input
           v-decorator="[
           'userName',
           {
            rules: [
              {
                required: true,
                message: 'Please input your Username!',
              },
            ]
           },
          ]"/>
        </a-form-item>
         <a-form-item>
           <a-input
           v-decorator="[
           'password',
           {
            rules: [
              {
                required: true,
                message: 'Please input your Password!',
              },
            ]
           },
          ]"/>
        </a-form-item>
        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
          <a-button type="primary" html-type="submit">
          Submit
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data(){
    return{
      form:this.$form.createForm(this, { name: 'login' }),
    }
  },
  methods:{
    handleSubmit(event) {
      event.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values);
          axios.post("http://ceshi5.dishait.cn/admin/login",{
            username:values.userName,
            password:values.password
          }).then((res)=>{
            console.log(res)
            localStorage.setItem("user",JSON.stringify(res.data.data));
            this.$router.push("/")
          }).catch((err)=>{
            console.log(err)
          })
        }
      });
    },
  }
}
</script>

<style scoped>
.login_container
{
  width: 100vw;
  height: 100vh;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
</style>